﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kooboo.HtmlFunc;
using Kooboo.HtmlFunc.Providers;
using Kooboo.CMS.SiteConverter.Providers;

namespace Kooboo.CMS.SiteConverter.Parser.Razor
{
    public class HtmlPartParser : ParserBase, IParser<IHtmlPart>
    {
        public static void FillResult(IHtmlPart obj, IParseResult result)
        {
            var html = NodeExtension.ReadString(obj.StartNode, obj.EndNode, !ParserSetting.RemoveFuncMarkers);
            result.Page.PagePositions.Add(new Kooboo.CMS.Sites.Models.HtmlPosition()
            {
                Html = html,
                LayoutPositionId = obj.OwnerPosition.Name,
                Order = obj.Order.HasValue ? obj.Order.Value : 0
            });
        }

        #region IParser<IHtmlPart> Members

        public void Parse(IHtmlPart obj)
        {
            // result
            FillResult(obj, this.Context.Result);
        }

        #endregion
    }
}
